package com.yuxl.ai.spg.controller;

import com.yuxl.ai.spg.entity.AiSpgEntity;
import com.yuxl.ai.spg.service.AiSpgEntityService;
import com.yuxl.common.core.domain.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;

@Tag(name = "知识图谱:实体")
@RequestMapping("/ai/spg/entity")
@RestController
public class AiSpgEntityController {
    @Resource
    private AiSpgEntityService aiSpgEntityService;

    @Operation(summary = "创建知识图谱实体")
    @PostMapping
    public Mono<AiSpgEntity> create(@RequestBody AiSpgEntity entity) {
        return aiSpgEntityService.create(entity);
    }

    @Operation(summary = "根据ID查询知识图谱实体")
    @GetMapping("/{id}")
    public Mono<R<AiSpgEntity>> getById(@Parameter(description = "知识图谱实体ID") @PathVariable Long id) {
        return aiSpgEntityService.findById(id)
                .map(R::ok);
    }

    @Operation(summary = "更新知识图谱实体")
    @PutMapping
    public Mono<R<AiSpgEntity>> updateById(@RequestBody AiSpgEntity entity) {
        return aiSpgEntityService.updateById(entity)
                .map(R::ok);
    }

    @Operation(summary = "删除知识图谱实体")
    @DeleteMapping("/{id}")
    public Mono<R<Void>> deleteById(@Parameter(description = "知识图谱实体ID") @PathVariable Long id) {
        return aiSpgEntityService.deleteById(id)
                .thenReturn(R.ok());
    }

    @Operation(summary = "条件查询知识图谱实体列表")
    @PostMapping("/list")
    public Mono<R<List<AiSpgEntity>>> list(@RequestBody AiSpgEntity entity) {
        return aiSpgEntityService.list(entity)
                .collectList()
                .map(R::ok);
    }

    @Operation(summary = "统计知识图谱实体数量")
    @PostMapping("/count")
    public Mono<R<Integer>> count(@RequestBody AiSpgEntity entity) {
        return aiSpgEntityService.count(entity)
                .map(R::ok);
    }

    @Operation(summary = "分页条件查询知识图谱实体")
    @PostMapping("/{page}/{size}/page")
    public Mono<R<List<AiSpgEntity>>> page(
            @RequestBody AiSpgEntity entity,
            @PathVariable int page,
            @PathVariable int size
    ) {
        return aiSpgEntityService.page(entity, page, size)
                .collectList()
                .map(R::ok);
    }
}
